package org.example.myleet.rosalind.mrna;

import org.example.myleet.rosalind.utils.RnaCodonReader;

import java.util.HashMap;
import java.util.Map;

public class Solution {

    private static final int MOD_BASE = 1000000;

    private final Map<String, Integer> aminoAcidMapPossibility;

    public Solution() {
        Map<String, String> codonMapAminoAcid = RnaCodonReader.getRnaCodonMapAminoAcid();
        aminoAcidMapPossibility = new HashMap<>();
        for (Map.Entry<String, String> entry : codonMapAminoAcid.entrySet()) {
            aminoAcidMapPossibility.put(entry.getValue(), aminoAcidMapPossibility.getOrDefault(entry.getValue(), 0) + 1);
        }
    }

    public int guessRnaNumber(String protein) {
        int guess = 1;
        for (int i = 0; i < protein.length(); ++i) {
            String aminoAcid = protein.substring(i, i + 1);
            guess *= aminoAcidMapPossibility.get(aminoAcid);
            guess %= MOD_BASE;
        }
        guess *= aminoAcidMapPossibility.get("Stop");
        guess %= MOD_BASE;
        return guess;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.guessRnaNumber("MA"));
        System.out.println(solution.guessRnaNumber("MDKRWSLQAGSLGPGATPGNDTILPIVGHFKESVKTCNLLSDPFNGYIILAAIEGCMTWNYKCEKFSHFYRNSTGTWGESIDYYVRCIGNSIHMGVPLHMQVKELESFPNACAIRINYEIVQHYGDRLYTTTGFFKHGNVMWLEKWHVNCYQCDRHKYRSQDWQIKSLQWTHDWPTCYSTIVPWHKKMNISFSFASSQMDTTLVYNANDRCISMYAIDVYWMRSDMTNLLQGPKKWSPWQGTKCQGNRHTEGDFSWPIKDPLMLPPIYLIPWGWQRRIVKIINGLNKDATSPHKHWYFKWAGQHQDFITDADWSSLSACNVPMDMDPPFTTQKYKLSGVGGRYHIWSACCWGKGYWYQSPEGLARWHDYLARPQMLQRDDNTEDRHSEMEDLRAWYMGMCQQFLHESGYAAKEGFEREPDSKDEDLPPPNIVQTDRTGIPHQPMTTQYYFALGRWIHSGKHCCMCYHCTGSNFPNRVLITHERVRETKNTAGIRHVKRCQHMNMPERQTRWNVLVYIKAPKDRSPCYHHVERSWPGLPHIFYPCWFAVTYHRAVGRQNYFHVGWHYGCRGHMSYFSQCLGREDFGQEGMRYDHTGCAMFRAMPVKYNFHVCNQSGPADYIRGARPWGTQHPQMYYWMINILAFDSQKPMRNHHNDVPQNRVQMHFYKPWAGWMQTTYAEIRCDPFCVWHMLYWWEIGHYFTCGWAEYGAMHASNIQYGRKMATTGQKGVEVECWHKMQQQRKDHNYSCHEPGWLNQCRSGMELIVMGIVGISHVWGKHICQYTDSLMMRYNNTVPIDRQHTHDERPLFGSVNFYLTHKHVQNQQGMEEYELGIEIKANLIENWTGHYKARSWAKTNKHEEKRMTCFQAMGIPQEAQPCHSDLCVYIEVGTCCSLYKLCIPVQTQITTRKKMGLYPNCTWVPMDCAHYSNMCPGDPRFDEQACMNQRHPTPANWPAGGLDGPESHKHGTLGTNALESHMIMLCCYCKLVEVEMKPWHWAVY"));
    }
}
